<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<link type="text/css" rel="stylesheet"
	href="static/bootstrap/css/bootstrap.min.css" />
</head>
<body>
	<script type="text/javascript"
		src="static/bootstrap/js/jquery-3.4.1.min.js"></script>
	<script type="text/javascript"
		src="static/bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$("#del").click(function(){
				var str="";
				var cc=$(":checkbox:checked");
				if(cc.length==0){
					alert("至少选中一行");
					return false;
				}
				$(":checkbox:checked").each(function(){
					str+=$(this).val()+",";
				});
				/* for(var i=0;i<cc.length;i++){
					str +=cc[i].value+",";} */
				var param={
			    		action:'deleteAll',
			    		ids:str
				};
			    $.get("goods",param,function(data){
			    	console.log(data,res);
			    },'json');
			    return false;
			});
			$("#delall").click(function(){
				//获得当前页中多选框的value值，即id的值
				var str="";
				var ck=$(":checkbox");
				for(var i=0;i<ck.length;i++){
					str +=ck[i].value+",";}
			    var param={
			    		action:'deleteAll',
			    		ids:str
			    };
			    $.get("goods",param,function(data){
			    	console.log(data,res);
			    },'json');
			    return false;
			});
		})
		</script>
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<span class="glyphicon glyphicon-trash"><a id="delall" href="goods?action=deleteAll">全部删除</a></span> 
				<span class="glyphicon glyphicon-remove"><a id="del" href="goods?action=deleteAll">选中删除</a></span> 
				<span class="glyphicon glyphicon-plus"><a href="goodsAdd.jsp">新增</a></span>
				
			</div>
		</div>
		<div class="row">
			<table class="table table-hover">
				<tr>
					<td></td>
					<td>商品编号</td>
					<td>商品名</td>
					<td>生产日期</td>
					<td>图片</td>
					<td>价格</td>
					<td>级别</td>
					<td>描述</td>
					<td>商品类别</td>
					<td>操作</td>
				</tr>
				<c:forEach items="${glist}" var="goods">
					<tr>
						<td><input type="checkbox" name="ids" value="${goods.gid}"></input></td>
						<td>${goods.getGid()}</td>
						<td>${goods.getGname()}</td>
						<td><f:formatDate value="${goods.getPubdate()}"
								pattern="yyyy-MM-dd" /></td>
						<td><img width="80px" height="80px" src="${goods.getPic()}" /></td>
						<td>${goods.getPrice() }</td>
						<td>${goods.getStar() }</td>
						<td>${goods.getInfo() }</td>
						<td><select name="good">
								<c:forEach items="${clist }" var="cl">
									<option
										<c:if test="${cl.gid==goods.typeid}">selected="selected"</c:if>
										value="${cl.gid }">${cl.gname }</option>
								</c:forEach>
						</select></td>
						<td><a href="goods?action=selectOneGoods&id=${goods.gid}">修改</a></td>
					</tr>
				</c:forEach>
				<tr>
					<td colspan="10" align="center">
						<nav aria-label="Page navigation">
							<ul class="pagination">
								<li><a
									href="goods?action=showGoods&page=${pb.page-1<1?1:(pb.page-1)}"
									aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
								</a></li>
								<li><a href="#">第${pb.page}页</a></li>
								<li><a href="#">共${pb.pageNum}页</a></li>
								<li><a href="#">每页显示${pb.rowsPerPage}条数据</a></li>
								<li><a href="#">共${pb.rowsNum}条数据</a></li>
								<li><a href="goods?action=showGoods&page=${pb.pageNum}">末页</a></li>
								<li><a href="goods?action=showGoods&page=${pb.page+1}"
									aria-label="Next"> <span aria-hidden="true">&raquo;</span>
								</a></li>
							</ul>
						</nav>
					</td>
				</tr>
			</table>
		</div>
</body>
</html>